home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld 1997 September
/
Macworld (1997-09).dmg
/
Shareware World
/
Utilities
/
Text Processing
/
AlphaLite.6.52
/
Tcl
/
SystemCode
/
copyRing.tcl
< prev
next >
Wrap
Text File
|
1996-08-15
|
3KB
|
130 lines
# Implementation of Emacs's kill ring. This is a paste ring.
if {[catch {set renamedRing}]} {
set renamedRing 1
rename copy oldCopy
rename cut oldCut
rename paste oldPaste
}
set ringDepth 5
set ringIn 0
set ringOut 0
set pasteStart 0
set pasteFinish 0
proc copy&Append {} {
set old [getScrap]
putScrap "$old[getSelect]"
message "Appended"
}
proc cut&Append {} {
set old [getScrap]
putScrap "$old[getSelect]"
deleteText [getPos] [selEnd]
message "Appended"
}
proc copy {} {
global copyring ringDepth ringIn
set len [expr {[selEnd] - [getPos]}]
if {!$len} {
if {[getMark] < [getPos]} {
set text [getText [getMark] [getPos]]
set len [expr [getPos] - [getMark]]
} else {
set text [getText [getPos] [getMark]]
set len [expr [getMark] - [getPos]]
}
if {![string length $text]} return
} else {
set text [getSelect]
}
set copyring([expr {$ringIn % $ringDepth}]) $text
incr ringIn
oldCopy
}
proc cut {{rect 0}} {
global copyring ringDepth ringIn intelCutPaste
set len [expr {[selEnd] - [getPos]}]
if {!$len} {
if {[getMark] < [getPos]} {
set text [getText [getMark] [getPos]]
set len [expr [getPos] - [getMark]]
} else {
set text [getText [getPos] [getMark]]
set len [expr [getMark] - [getPos]]
}
if {![string length $text]} return
} else {
set text [getSelect]
}
set copyring([expr {$ringIn % $ringDepth}]) $text
incr ringIn
oldCut
if {$intelCutPaste && !$rect} {
if {[isWhite 0] && [isWhite -1]} {
backSpace
}
}
}
proc paste {{rect 0}} {
global copyring ringDepth ringIn ringOut intelCutPaste pasteStart pasteFinish
set intel 0
set ringOut [expr {($ringIn - 1) % $ringDepth}]
if {!$rect && $intelCutPaste} {
set left -1
set right [expr [selEnd] - [getPos]]
if {[isWhite $right] && [isChar $left]} {
clear
insertText " "
} elseif {[isWhite $left] && [isChar $right]} {set intel 1}
}
oldPaste
set pasteStart [getMark]
set pasteFinish [getPos]
if {$intel && ([lookAt [expr [getPos]-1]] != "\r")} {
insertText " "
}
}
proc isWhite {off} {
set c [lookAt [expr [getPos] + $off]]
return [expr {($c == " ")}]
}
proc isChar {off} {
set c [lookAt [expr [getPos] + $off]]
return [expr {[string match {[a-z]} $c]}]
}
proc pastePop {} {
global copyring ringDepth ringIn ringOut pasteFinish pasteStart
if {!$ringIn} { beep; return}
set ringOut [expr $ringOut-1]
if {$ringOut < 0} {set ringOut [expr (($ringDepth > $ringIn) ? $ringIn : $ringDepth) - 1]}
replaceText $pasteStart $pasteFinish $copyring($ringOut)
set pasteFinish [expr $pasteStart + [string length $copyring($ringOut)]]
}